'use strict';

/**
 * @param {number} x
 * @return {number}
 */
var reverse = function(x) {
  const sig = x < 0;
  const abs = Math.abs(x);
  if (abs >= 2147483647) {
    return 0;
  }
  const str = `${abs}`;
  const v = str.split('').reverse().join('');
  let n = Number(v);
  if (n >= 2147483647) {
    return 0;
  }
  if (sig) {
    n = -n;
  }
  return n;
};
